package com.db4o.odbgen;

import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * 
 * This is the base class of all exceptions thrown from OdbGen.
 * @author liviug
 */
public class OdbgenException extends Exception{
    private static final long serialVersionUID = -7315614888532922782L;
    private Exception innerException;

    public OdbgenException(String message, Object...args){
        super(String.format(message, args));
    }
    public OdbgenException(Exception inner, String message, Object...args){
        super(String.format(message, args));
        this.innerException = inner;
    }
    
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        if(this.innerException!=null){
            sb.append(", ");
            sb.append(innerException.toString());
        }
        return sb.toString();
    }
    
    @Override
    public void printStackTrace() {
        super.printStackTrace();
        if(this.innerException!=null){
            innerException.printStackTrace();
        }
    }
    
    @Override
    public void printStackTrace(PrintStream s) {
        super.printStackTrace(s);
        if(this.innerException!=null){
            innerException.printStackTrace(s);
        }
    }
    
    @Override
    public void printStackTrace(PrintWriter s) {
        super.printStackTrace(s);
        if(this.innerException!=null){
            innerException.printStackTrace(s);
        }
    }
}
